const Store = require('electron-store')
Store.initRenderer()
const store = new Store()
console.log(store.path, 'store.path')

//注册到主进程的事件
export function register(ipcMain) {
  //存储信息
  ipcMain.on('setValue', function (event, key, value) {
    console.log('store.path', store.path)
    store.set(key, value)
  })

  //获取信息
  ipcMain.handle('getValue', async (event, key) => {
    console.log(store.get(key), 'store.get(key)')
    return store.get(key)
    // return new Promise((resolve) => {
    //   console.log(store.get(key), 'store.get(key)')
    //   resolve(store.get(key))
    // })
  })

  //删除信息
  ipcMain.on('deleteValue', function (event, key) {
    store.delete(key)
  })
}

export default store
